const router = require('koa-router')()
const dbs = require('../mysql').isconnect()

router.post('/barrier', async ctx => {
  let { page } = ctx.request.body
  let res = await dbs.other(
    `select * from quizzes limit ${(page = page ? page : 0)},10;`
  )
  ctx.body = { code: 200, result: res.message }
})

router.post('/CareerList', async ctx => {
  let { page } = ctx.request.body
  if (page == undefined || page == '') {
    page = 0
  }
  let res = await dbs.other(`select * from quizzes limit ${page},15;`)
  ctx.body = { code: 200, result: res.message }
})

router.get('/allType', async ctx => {
  let res = await dbs.other('SELECT type, COUNT(*) from quizzes GROUP BY type ')
  if (res.code == 1) {
    ctx.body = { code: 200, result: res.message }
  }
})

router.post('/typeQuestion', async ctx => {
  let { type } = ctx.request.body
  if (type === undefined || type === '') {
    ctx.body = { code: 10000, result: '请选择类型' }
  } else {
    let res = await dbs.find('*', 'quizzes', `type='${type}'`)
    ctx.body = { code: 200, result: res }
  }
})

module.exports = router.routes()
